package io.osw.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.osw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.osw.modules.sys.entity.TblBudgetCalendarEntity;
import io.osw.modules.sys.service.TblBudgetCalendarService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 预算日历
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-06 21:44:58
 */
@RestController
@RequestMapping("sys/tblbudgetcalendar")
public class TblBudgetCalendarController extends AbstractController{
    @Autowired
    private TblBudgetCalendarService tblBudgetCalendarService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblbudgetcalendar:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblBudgetCalendarService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{calId}")
    @RequiresPermissions("sys:tblbudgetcalendar:info")
    public R info(@PathVariable("calId") Long calId){
        TblBudgetCalendarEntity tblBudgetCalendar = tblBudgetCalendarService.selectById(calId);

        return R.ok().put("tblBudgetCalendar", tblBudgetCalendar);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblbudgetcalendar:save")
    public R save(@RequestBody TblBudgetCalendarEntity tblBudgetCalendar){
        tblBudgetCalendar.setCreateTime(new Date());
        tblBudgetCalendar.setCreateBy(getUserId());
        tblBudgetCalendar.setCompanyId(getUser().getCompanyId());
        tblBudgetCalendarService.insert(tblBudgetCalendar);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblbudgetcalendar:update")
    public R update(@RequestBody TblBudgetCalendarEntity tblBudgetCalendar){
        ValidatorUtils.validateEntity(tblBudgetCalendar);
        tblBudgetCalendar.setUpdateTime(new Date());
        tblBudgetCalendar.setUpdateBy(getUserId());
        tblBudgetCalendarService.updateAllColumnById(tblBudgetCalendar);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblbudgetcalendar:delete")
    public R delete(@RequestBody Long[] calIds){
        tblBudgetCalendarService.deleteBatchIds(Arrays.asList(calIds));

        return R.ok();
    }

}
